package com.cjb.cloudsecurity.userMsg.service.impl;

import com.cjb.cloudsecurity.userMsg.entity.SysUserEntity;
import com.cjb.cloudsecurity.userMsg.entity.UserDetail;
import com.cjb.cloudsecurity.userMsg.service.SysUserDetailsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

/**
 * @Author chenjinbin
 * @Package IntelliJ IDEA
 * @Class SysUserDetailsServiceImpl
 * @Date 2023-08-12 23:06
 */
@Service
public class SysUserDetailsServiceImpl implements SysUserDetailsService {
    /**
     * 日志
     */
    private final static Logger log = LoggerFactory.getLogger(SysUserDetailsService.class);

    @Override
    public UserDetails getUserDetails(SysUserEntity userEntity) {
        // 转换成UserDetail对象
        UserDetail userDetail = convertDetail(userEntity);

        return userDetail;
    }
    private UserDetail convertDetail(SysUserEntity entity){
        if ( entity == null ) {
            return null;
        }
        UserDetail userDetail = new UserDetail();
        userDetail.setId( entity.getId() );
        userDetail.setUsername( entity.getUsername() );
        userDetail.setPassword(entity.getPassword());
        userDetail.setRealName( entity.getRealName() );
        userDetail.setAvatar( entity.getAvatar() );
        userDetail.setGender( entity.getGender() );
        userDetail.setEmail( entity.getEmail() );
        userDetail.setMobile( entity.getMobile() );
        userDetail.setOrgId( entity.getOrgId() );
        userDetail.setStatus( entity.getStatus() );
        userDetail.setSuperAdmin( entity.getSuperAdmin() );
        userDetail.setTenantId( entity.getTenantId());
        return userDetail;
    }

}
